import {
  Component,
  OnInit,
  ViewEncapsulation,
  ChangeDetectionStrategy,
  Input,
  ChangeDetectorRef,
  Output,
  EventEmitter
} from '@angular/core';
import {Router} from '@angular/router';
import {ToolsService} from '../../../../shared/service/tools/tools.service';
import {CommunityService} from '../../community.service';
import {Subject} from 'rxjs';

@Component({
  selector: 'circle-feed',
  templateUrl: './circle-feed.component.html',
  styleUrls: ['./circle-feed.component.scss'],
  encapsulation: ViewEncapsulation.None
})
export class CircleFeedComponent implements OnInit {
  @Input() feeds;
  @Input() haveData;
  @Input() showMark;
  @Input() showDel;
  @Input() showTag;
  @Output() remove = new EventEmitter();
  public ngUnsubscribe: Subject<void> = new Subject<void>();

  constructor(private tools: ToolsService,
              private communityService: CommunityService) {
  }

  /**
   * @description 删除圈子帖子
   * @author ouyqx-691
   * @date 2017-12-18
   */
  delFeed(feedId: number) {
    this.tools.present({title: '确定删除？', cancelBtn: true}).then(status => {
      if (status) {
        this.communityService.delFeed(feedId).takeUntil(this.ngUnsubscribe).subscribe(res => {
          if (res.result === '0') {
            this.tools.showToast('删除成功');
            this.remove.emit(feedId);
          }
        });
      }
    });
  }

  ngOnInit() {

  }
}
